home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / c / qtools0.2-src.lha / src / libqsys / generic-debug.h next >
Encoding:
C/C++ Source or Header  |  1998-07-16  |  4.8 KB  |  89 lines

  1. #ifndef    DEBUG_H
  2. #define    DEBUG_H
  3.  
  4. #ifndef    ALLPERMS
  5. #define    ALLPERMS    0x0777
  6. #endif
  7.  
  8. #ifdef    DEBUG_C
  9. # define __assert(file, func, line)    (eprintf("(%s %s %u)\n", file, func, line), abort(), 0)
  10. # ifndef HAVE_LIBDBMALLOC
  11. #  include <malloc.h>
  12. #  define __memset(mem, pat, len)    ((void)      ((mem)        ? memset(mem, pat, len)     : __assert(__FILE__, __FUNCTION__, __LINE__)))
  13. #  define __memcpy(dst, src, len)    ((void)      (((dst) && (src)) ? memcpy(dst, src, len)     : __assert(__FILE__, __FUNCTION__, __LINE__)))
  14. #  define __bzero(mem, len)        ((void)      ((mem)        ? bzero(mem, len)         : __assert(__FILE__, __FUNCTION__, __LINE__)))
  15. #  define __strcpy(dst, src)        ((void)      (((dst) && (src)) ? strcpy(dst, src)         : __assert(__FILE__, __FUNCTION__, __LINE__)))
  16. #  define __strncpy(dst, src, len)    ((void)      (((dst) && (src)) ? strncpy(dst, src, len)     : __assert(__FILE__, __FUNCTION__, __LINE__)))
  17. #  define __strcat(dst, src)        ((void)      (((dst) && (src)) ? strcat(dst, src)         : __assert(__FILE__, __FUNCTION__, __LINE__)))
  18. #  define __strncat(dst, src, len)    ((void)      (((dst) && (src)) ? strncat(dst, src, len)     : __assert(__FILE__, __FUNCTION__, __LINE__)))
  19. #  define __strcmp(dst, src)        ((int)      (((dst) && (src)) ? strcmp(dst, src)         : __assert(__FILE__, __FUNCTION__, __LINE__)))
  20. #  define __strncmp(dst, src, len)    ((int)      (((dst) && (src)) ? strncmp(dst, src, len)     : __assert(__FILE__, __FUNCTION__, __LINE__)))
  21. #  define __strlen(str)            ((int)      ((str)        ? strlen(str)         : __assert(__FILE__, __FUNCTION__, __LINE__)))
  22. #  define __strchr(mem, pat)        ((char *) ((mem)        ? strchr(mem, pat)         : __assert(__FILE__, __FUNCTION__, __LINE__)))
  23. #  define __strrchr(mem, pat)        ((char *) ((mem)        ? strrchr(mem, pat)         : __assert(__FILE__, __FUNCTION__, __LINE__)))
  24. #  define __index(mem, pat)        ((char *) ((mem)        ? index(mem, pat)         : __assert(__FILE__, __FUNCTION__, __LINE__)))
  25. #  define __rindex(mem, pat)        ((char *) ((mem)        ? rindex(mem, pat)         : __assert(__FILE__, __FUNCTION__, __LINE__)))
  26. # else
  27. #  include <dbmalloc.h>
  28. #  define __memset    memset
  29. #  define __memcpy    memcpy
  30. #  define __bzero    bzero
  31. #  define __strcpy    strcpy
  32. #  define __strncpy    strncpy
  33. #  define __strcat    strcat
  34. #  define __strncat    strncat
  35. #  define __strcmp    strcmp
  36. #  define __strncmp    strncmp
  37. #  define __strlen    strlen
  38. #  define __strchr    strchr
  39. #  define __strrchr    strrchr
  40. #  define __index    index
  41. #  define __rindex    rindex
  42. # endif
  43. # define __strcasecmp(dst, src)        ((int)      (((dst) && (src)) ? strcasecmp(dst, src)     : __assert(__FILE__, __FUNCTION__, __LINE__)))
  44. # define __strncasecmp(dst, src, len)    ((int)      (((dst) && (src)) ? strncasecmp(dst, src, len) : __assert(__FILE__, __FUNCTION__, __LINE__)))
  45. # define __fopen(name, mode)        ((FILE *) ((name)        ? fopen(name, mode)         : __assert(__FILE__, __FUNCTION__, __LINE__)))
  46. # define __fclose(handle)        ((void)      ((handle)        ? fclose(handle)         : __assert(__FILE__, __FUNCTION__, __LINE__)))
  47. # define __fread(buf, l1, l2, hl)    ((int)      (((buf) && (hl))  ? fread(buf, l1, l2, hl)     : __assert(__FILE__, __FUNCTION__, __LINE__)))
  48. # define __fwrite(buf, l1, l2, h)    ((int)      (((buf) && (h))   ? fwrite(buf, l1, l2, h)     : __assert(__FILE__, __FUNCTION__, __LINE__)))
  49. # define __ftell(handle)        ((int)      ((handle)        ? ftell(handle)         : __assert(__FILE__, __FUNCTION__, __LINE__)))
  50. # define __fseek(hdl, offs, mode)    ((void)      ((hdl)        ? fseek(hdl, offs, mode)     : __assert(__FILE__, __FUNCTION__, __LINE__)))
  51. # define __open(name, flags)        ((HANDLE) ((name)        ? open(name, flags, ALLPERMS): __assert(__FILE__, __FUNCTION__, __LINE__)))
  52. # define __close(handle)        ((void)      ((handle > 0)        ? close(handle)         : __assert(__FILE__, __FUNCTION__, __LINE__)))
  53. # define __read(hl, buf, len)        ((int)      (((buf) && (hl>0))? read(hl, buf, len)     : __assert(__FILE__, __FUNCTION__, __LINE__)))
  54. # define __write(hl, buf, len)        ((int)      (((buf) && (hl>0))? write(hl, buf,len)     : __assert(__FILE__, __FUNCTION__, __LINE__)))
  55. # define __ltell(handle)        ((int)      ((handle > 0)        ? lseek(handle, 0, SEEK_CUR) : __assert(__FILE__, __FUNCTION__, __LINE__)))
  56. # define __lseek(hdl, offs, mode)    ((int)      ((hdl > 0)        ? lseek(hdl, offs, mode)     : __assert(__FILE__, __FUNCTION__, __LINE__)))
  57. #else
  58. # define __memset    memset
  59. # define __memcpy    memcpy
  60. # define __bzero    bzero
  61. # define __strcpy    strcpy
  62. # define __strncpy    strncpy
  63. # define __strcat    strcat
  64. # define __strncat    strncat
  65. # define __strcmp    strcmp
  66. # define __strncmp    strncmp
  67. # define __strlen    strlen
  68. # define __strchr    strchr
  69. # define __strrchr    strrchr
  70. # define __index    index
  71. # define __rindex    rindex
  72. # define __strcasecmp    strcasecmp
  73. # define __strncasecmp    strncasecmp
  74. # define __fopen    fopen
  75. # define __fclose    fclose
  76. # define __fread    fread
  77. # define __fwrite    fwrite
  78. # define __ftell    ftell
  79. # define __fseek    fseek
  80. # define __open(h, f)    open(h, f, ALLPERMS)
  81. # define __close    close
  82. # define __read        read
  83. # define __write    write
  84. # define __ltell(hl)    lseek(hl, 0, SEEK_CUR)
  85. # define __lseek    lseek
  86. #endif
  87.  
  88. #endif
  89.